package com.link.base.base.cachemanager.controller;

import javax.annotation.Resource;

import com.link.base.base.cachemanager.model.CacheManager;
import com.link.base.base.cachemanager.service.CacheManagerService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 缓存器管理-缓存器管理 
 *
 * @author 秦学刚
 * @date 2020/05/08 09:23
 */
@Controller
@RequestMapping("/link/cacheManager")
public class CacheManagerController extends BasicController<CacheManager> {
 
    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private CacheManagerService cacheManagerService;

    @Override
    public BasicService<CacheManager> getBasicService() throws Exception {
        return cacheManagerService;
    }

    /**
     * 刷新缓存
     *
     * @author 秦学刚
     * @date 2018年12月4日
     * @return
     */
    @RequestMapping(value = "/refreshCache")
    @ResponseBody
    public Map<String, Object> refreshCache() {
        Map<String, Object> result = new HashMap<String, Object>(2);
        try {
            cacheManagerService.refreshCache();
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }


    /**
     * 刷新缓存
     *
     * @author 秦学刚
     * @date 2018年12月4日
     * @return
     */
    @RequestMapping(value = "/clearCache")
    @ResponseBody
    public Map<String, Object> clearCache(@JsonParam CacheManager cacheManager) {
        Map<String, Object> result = new HashMap<String, Object>(2);
        try {
            cacheManagerService.clearCache(cacheManager);
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

}
